home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.image;
-
- import java.awt.image.ImageConsumer;
- import java.awt.image.IndexColorModel;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Hashtable;
-
- public class GifImageDecoder extends ImageDecoder {
- private final boolean verbose = false;
- private static final int IMAGESEP = 44;
- private static final int EXBLOCK = 33;
- private static final int EX_GRAPHICS_CONTROL = 249;
- private static final int EX_COMMENT = 254;
- private static final int EX_APPLICATION = 255;
- private static final int TERMINATOR = 59;
- private static final int INTERLACEMASK = 64;
- private static final int COLORMAPMASK = 128;
- PixelStore8 store;
- int num_colors;
- byte[] colormap;
- IndexColorModel model;
- Hashtable props = new Hashtable();
- private static final int normalflags = 30;
- private static final int interlaceflags = 29;
-
- public GifImageDecoder(InputStreamImageSource var1, InputStream var2) {
- super(var1, var2);
- }
-
- public synchronized boolean catchupConsumer(InputStreamImageSource var1, ImageConsumer var2) {
- return this.store == null || this.store.replay(var1, var2);
- }
-
- public synchronized void makeStore(int var1, int var2) {
- this.store = new PixelStore8(var1, var2);
- }
-
- private static void error(String var0) throws ImageFormatException {
- throw new ImageFormatException(var0);
- }
-
- boolean readBytes(byte[] var1, int var2, int var3) {
- while(var3 > 0) {
- int var4;
- try {
- var4 = super.input.read(var1, var2, var3);
- } catch (IOException var5) {
- var4 = -1;
- }
-
- if (var4 < 0) {
- return false;
- }
-
- var2 += var4;
- var3 -= var4;
- }
-
- return true;
- }
-
- public void produceImage() throws IOException, ImageFormatException {
- int var1 = -1;
-
- try {
- this.readHeader();
-
- label248:
- while(true) {
- switch (super.input.read()) {
- case -1:
- return;
- case 33:
- int var4;
- String var21;
- switch (var4 = super.input.read()) {
- case 249:
- byte[] var5 = new byte[6];
- if (!this.readBytes(var5, 0, 6)) {
- return;
- }
-
- if (var5[0] != 4 || var5[5] != 0) {
- return;
- }
-
- var1 = var5[4] & 255;
- continue;
- case 254:
- case 255:
- default:
- var21 = "";
- }
-
- while(true) {
- int var6 = super.input.read();
- if (var6 == 0) {
- if (var4 == 254) {
- this.props.put("comment", var21);
- }
- continue label248;
- }
-
- byte[] var7 = new byte[var6];
- if (!this.readBytes(var7, 0, var6)) {
- return;
- }
-
- if (var4 == 254) {
- var21 = var21 + new String(var7, 0);
- }
- }
- case 44:
- try {
- this.model = new IndexColorModel(8, this.num_colors, this.colormap, 0, false, var1);
- this.colormap = null;
- if (this.readImage()) {
- this.store.imageComplete();
- if (this.store.getBitState() != 2) {
- super.source.setPixelStore(this.store);
- }
-
- super.source.imageComplete(3);
- return;
- }
- } catch (ArrayIndexOutOfBoundsException var19) {
- }
-
- return;
- case 59:
- return;
- default:
- return;
- }
- }
- } finally {
- try {
- super.input.close();
- } catch (IOException var18) {
- }
-
- }
- }
-
- private void readHeader() throws IOException, ImageFormatException {
- byte[] var1 = new byte[13];
- if (!this.readBytes(var1, 0, 13)) {
- throw new IOException();
- } else if (var1[0] == 71 && var1[1] == 73 && var1[2] == 70) {
- int var2 = var1[10] & 255;
- if ((var2 & 128) == 0) {
- throw new ImageFormatException("no global colormap in GIF file.");
- } else {
- this.num_colors = 1 << (var2 & 7) + 1;
- if (var1[12] != 0) {
- this.props.put("aspectratio", "" + (double)((var1[12] & 255) + 15) / (double)64.0F);
- }
-
- this.colormap = new byte[this.num_colors * 3];
- if (!this.readBytes(this.colormap, 0, this.num_colors * 3)) {
- throw new IOException();
- }
- }
- } else {
- throw new ImageFormatException("not a GIF file.");
- }
- }
-
- private native boolean parseImage(int var1, int var2, boolean var3, int var4, byte[] var5, byte[] var6);
-
- private int sendPixels(int var1, int var2, byte[] var3) {
- int var4 = super.source.setPixels(0, var1, var2, 1, this.model, var3, 0, var2);
- if (this.store.setPixels(0, var1, var2, 1, var3, 0, var2)) {
- ++var4;
- }
-
- return var4;
- }
-
- private boolean readImage() throws IOException {
- long var1 = 0L;
- byte[] var3 = new byte[259];
- if (!this.readBytes(var3, 0, 10)) {
- throw new IOException();
- } else {
- int var4 = var3[4] & 255 | var3[5] << 8;
- int var5 = var3[6] & 255 | var3[7] << 8;
- boolean var6 = (var3[8] & 64) != 0;
- int var7 = var3[9] & 255;
- super.source.setDimensions(var4, var5);
- this.makeStore(var4, var5);
- super.source.setProperties(this.props);
- this.store.setProperties(this.props);
- super.source.setColorModel(this.model);
- this.store.setColorModel(this.model);
- int var8 = var6 ? 29 : 30;
- super.source.setHints(var8);
- this.store.setHints(var8);
- byte[] var9 = new byte[var4];
- boolean var10 = this.parseImage(var4, var5, var6, var7, var3, var9);
- return var10;
- }
- }
- }
-